using System;

namespace PhotoFramePublishingPlugin
{
    internal class ImageSize : IEquatable<ImageSize>
    {
        public string Description { get; private set; }
        public int Width { get; private set; }
        public int Height { get; private set; }

        public bool IsValid
        {
            get { return Width != 0 && Height != 0; }
        }

        public ImageSize(string description, int width, int height)
        {
            Description = description;
            Width = width;
            Height = height;
        }

        public bool Equals(ImageSize other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return other.Width == Width && other.Height == Height;
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof(ImageSize)) return false;
            return Equals((ImageSize)obj);
        }

        public override int GetHashCode()
        {
            unchecked
            {
                return (Width * 397) ^ Height;
            }
        }

        public static bool operator ==(ImageSize left, ImageSize right)
        {
            return Equals(left, right);
        }

        public static bool operator !=(ImageSize left, ImageSize right)
        {
            return !Equals(left, right);
        }

        public override string ToString()
        {
            return string.Format("{0}: {1} x {2}", Description, Width, Height);
        }
    }
}